/**
 * Project Name:api-webhook
 * File Name:EventListener.java
 * Package Name:com.example.service.webhook.service
 * Date:2016年7月19日下午2:24:31
 * Copyright (c) 2016, yuandong@51dojo.com All Rights Reserved.
 */

package com.example.service.webhook.listener;

import com.example.service.webhook.business.alipay.billitem.AlipayBillTask;
import com.example.service.webhook.business.alipay.service.AlipayService;
import com.example.service.webhook.business.bank.billitem.BankBillTask;
import com.example.service.webhook.business.bank.service.BankBillService;
import com.example.service.webhook.business.carrier.billitem.CarrierBillTask;
import com.example.service.webhook.business.carrier.billitem.CarrierReportTask;
import com.example.service.webhook.business.carrier.service.CarrierBillService;
import com.example.service.webhook.business.carrier.service.CarrierReportService;
import com.example.service.webhook.business.chsi.billitem.ChsiBillTask;
import com.example.service.webhook.business.chsi.service.ChsiService;
import com.example.service.webhook.business.court.billitem.ZhixingCourtBillTask;
import com.example.service.webhook.business.court.service.ZhixingCourtService;
import com.example.service.webhook.business.email.billitem.EmailBillTask;
import com.example.service.webhook.business.email.service.BillService;
import com.example.service.webhook.business.fund.billitem.FundTask;
import com.example.service.webhook.business.fund.service.FundService;
import com.example.service.webhook.business.insurance.billitem.InsuranceBillTask;
import com.example.service.webhook.business.insurance.service.InsuranceService;
import com.example.service.webhook.business.jingdong.billitem.JdBillTask;
import com.example.service.webhook.business.jingdong.service.JingdongService;
import com.example.service.webhook.business.qq.billitem.QqBillTask;
import com.example.service.webhook.business.qq.service.QqService;
import com.example.service.webhook.business.security.billitem.SecurityTask;
import com.example.service.webhook.business.security.service.SecurityService;
import com.example.service.webhook.business.taobao.billitem.TaobaoTask;
import com.example.service.webhook.business.taobao.service.TaobaoService;
import com.example.service.webhook.business.zhengxin.billitem.ZhengxinTask;
import com.example.service.webhook.business.zhengxin.service.ZhengxinService;
import com.google.common.eventbus.Subscribe;
import org.springframework.context.ApplicationContext;

/**
 * ClassName:EventListener <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason:   TODO ADD REASON. <br/>
 * Date:     2016年7月19日 下午2:24:31 <br/>
 *
 * @author yuandong
 * @see
 * @since JDK 1.6
 */
public class EventListener {

    private ApplicationContext applicationContext;


    public EventListener(ApplicationContext context) {
        applicationContext = context;
    }

    @Subscribe
    public void emailListener(EmailBillTask emailbill) {
        System.out.println("event:" + emailbill.getEmailId());
        try {
            BillService billService = (BillService) applicationContext.getBean("billService");
            billService.fetchBill(emailbill);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe
    public void bankListener(BankBillTask bankBill) {

        System.out.println("event:" + bankBill.getTaskId());

        try {
            BankBillService billService = (BankBillService) applicationContext.getBean("bankBillService");
            billService.fetchBill(bankBill);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    @Subscribe
    public void carrierListener(CarrierBillTask carrierBill) {

        System.out.println("mobile:" + carrierBill.getMobile());

        try {
            CarrierBillService billService = (CarrierBillService) applicationContext.getBean("carrierBillService");
            billService.fetchBill(carrierBill);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe
    public void ReportListener(CarrierReportTask reportTask) {

        System.out.println("mobile:" + reportTask.getMobile());

        try {
            CarrierReportService reportService = (CarrierReportService) applicationContext.getBean("carrierReportService");
            reportService.fetchReport(reportTask);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe
    public void chsiListener(ChsiBillTask chsiBill) {

        System.out.println("taskId:" + chsiBill.getTaskId());

        try {
            ChsiService billService = (ChsiService) applicationContext.getBean("chsiService");
            billService.fetchBill(chsiBill);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Subscribe
    public void taobaoListener(TaobaoTask taobao) {

        System.out.println("account:" + taobao.getAccount());

        try {
            TaobaoService billService = (TaobaoService) applicationContext.getBean("taobaoService");
            billService.fetchBill(taobao);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe
    public void fundListener(FundTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            FundService billService = (FundService) applicationContext.getBean("fundService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Subscribe
    public void alipayListener(AlipayBillTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            AlipayService billService = (AlipayService) applicationContext.getBean("alipayService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Subscribe
    public void jingdongListener(JdBillTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            JingdongService billService = (JingdongService) applicationContext.getBean("jingdongService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Subscribe
    public void qqListener(QqBillTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            QqService billService = (QqService) applicationContext.getBean("qqService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Subscribe
    public void zhengxinListener(ZhengxinTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            ZhengxinService billService = (ZhengxinService) applicationContext.getBean("zhengxinService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe
    public void insuranceListener(InsuranceBillTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            InsuranceService billService = (InsuranceService) applicationContext.getBean("insuranceService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Subscribe
    public void securityListener(SecurityTask task) {

        System.out.println("taskId:" + task.getTaskId());

        try {
            SecurityService billService = (SecurityService) applicationContext.getBean("securityService");
            billService.fetchBill(task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Subscribe
    public void zhixingCourtListener(ZhixingCourtBillTask task){

        System.out.println("taskId:" + task.getTaskId());

        try {
            ZhixingCourtService zhixingCourtService = (ZhixingCourtService) applicationContext.getBean("zhixingCourtService");

            zhixingCourtService.fetchBill(task);

        }catch (Exception ex){
            ex.printStackTrace();
        }

    }


}
  
